package vip.george.user.controller;

import lombok.extern.slf4j.Slf4j;
import org.apache.catalina.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import vip.george.common.constant.ResultCodeEnum;
import vip.george.common.dto.ResultVO;
import vip.george.common.entity.ScUser;
import vip.george.common.exception.AppException;
import vip.george.user.dao.UserDao;

import java.util.Objects;

/**
 * @author george
 * @since 2023/7/5
 * <p></p>
 */
@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private UserDao userDao;

    @Value("${server.port}")
    private String port;


    /**
     * 根据id查询单个用户，并且测试全局异常捕获
     * @param id
     * @return
     */
    @GetMapping("/queryUser")
    public ResultVO<ScUser> queryUser(@RequestParam Long id){
        log.info("查询用户，使用的服务端口为：{}",port);
        log.info("查询用户，使用的服务端口为：{}",port);
        ScUser user = userDao.selectById(id);
        if (Objects.isNull(user)){
            throw new AppException(ResultCodeEnum.USER_NOT_EXIST);
        }
//        int a = 1/0;
        return ResultVO.success(user);
    }
}
